/*
 * @Author: your name
 * @Date: 2021-10-16 15:48:47
 * @LastEditTime: 2021-10-16 15:52:29
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \luogu\动态规划\模板问题\P2925 Hay For Sale S\main.cpp
 */
#include<iostream>
using namespace std;
#include<algorithm>

int f[50010];

int main(){
    int C,H;
    cin >> C >> H;
    for(int i=1; i<=H; i++){
        int v;
        cin >> v;
        for(int j=C; j>=v; j--){
            f[j] = max(f[j],f[j-v]+v);
        }
    }
    cout << f[C] << endl;
    return 0;
}